import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

enum SpinKitType {
  CubeGrid,
  FadingCircle,
  DoubleBounce,
}

class Spin extends StatelessWidget {
  SpinKitType type;
  Color color;
  double size;

  /// SpinKitType Spin
  /// * [type] 动画类型
  /// * [color] Color|验证
  /// * [size] double|大小
  Spin({
    SpinKitType type = SpinKitType.FadingCircle,
    Color color = const Color.fromRGBO(58, 98, 237, .9),
    double size = 45,
  })  : this.type = type,
        this.color = color,
        this.size = size;

  @override
  Widget build(BuildContext context) => createSpink(type, color, size);

  /// 创建Spink
  /// * [type] SpinKitType|动画类型|详见：SpinKitType
  Widget createSpink(SpinKitType type, Color color, double size) {
    switch (type) {
      case SpinKitType.CubeGrid:
        return SpinKitCubeGrid(color: color, size: size);
      case SpinKitType.DoubleBounce:
        return SpinKitDoubleBounce(color: color, size: size);
      case SpinKitType.FadingCircle:
        return SpinKitFadingCircle(color: color, size: size);
    }
  }
}
